package com.guo.core.framework.suanfa;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @projectName: 接口梳理
 * @package: com.guo.core.framework.suanfa
 * @className: HashUtils
 * @author: zhangcan30
 * @description: TODO
 * @date: 2023/7/18 10:12
 * @version: 1.0
 */
public class HashUtils {
    public static String generateHash(String... fields) throws NoSuchAlgorithmException {
        StringBuilder sb = new StringBuilder();
        for (String field : fields) {
            sb.append(field);
        }
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] hash = md.digest(sb.toString().getBytes(StandardCharsets.UTF_8));
        StringBuilder hexString = new StringBuilder();
        for (byte b : hash) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();
    }

    public static void main(String[] args) {
        String a="aaa";
        a=a+null;
        System.out.println(a);
    }
}
